<%@page import="entity.Category"%>
<%@page import="service.CategoryServiceLocal"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<!--  start nav-outer-repeat................................................................................................. START -->
<div class="nav-outer-repeat"> 
<!--  start nav-outer -->
<div class="nav-outer"> 

		<!-- start nav-right -->
		<div id="nav-right">
                        <div class="showhide-account">&nbsp;</div>
			<div class="nav-divider">&nbsp;</div>
			<a href="<c:url value="/admin/login.jsp" />" id="logout"><img src="<c:url value="/layout/default/shared/nav/nav_logout.gif" />" width="64" height="14" alt="" /></a>
			<div class="clear">&nbsp;</div>
		
		</div>
		<!-- end nav-right -->


		<!--  start nav -->
		<div class="nav">
		<div class="table">
		
		                    
		<ul class="current"><li><a href="<c:url value="/admin/view_product.jsp" />"><b>Sản Phẩm</b><!--[if IE 7]><!--></a><!--<![endif]-->
		<!--[if lte IE 6]><table><tr><td><![endif]-->
		<div class="select_sub show">
			<ul class="sub">
				<li><a href="<c:url value="/admin/view_product.jsp" />">Xem Sản Phẩm</a></li>
				<li><a href="<c:url value="/admin/update_product.jsp" />">Cập Nhật Sản Phẩm</a></li>
				<li class="sub_show"><a href="<c:url value="/admin/add_product.jsp" />">Thêm Sản Phẩm</a></li>
			</ul>
		</div>
		<!--[if lte IE 6]></td></tr></table></a><![endif]-->
		</li>
		</ul>
		
		<div class="nav-divider">&nbsp;</div>
		
		<ul class="select"><li><a href="#nogo"><b>Loại Sản Phẩm</b><!--[if IE 7]><!--></a><!--<![endif]-->
		<!--[if lte IE 6]><table><tr><td><![endif]-->
		<div class="select_sub">
			<ul class="sub">
				<li><a href="#nogo">Thêm Loại Sản Phẩm</a></li>
			</ul>
		</div>
		<!--[if lte IE 6]></td></tr></table></a><![endif]-->
		</li>
		</ul>
		
		<div class="nav-divider">&nbsp;</div>
		
		<ul class="select"><li><a href="<c:url value="/admin/update_order.jsp" />"><b>Đơn Hàng</b><!--[if IE 7]><!--></a><!--<![endif]-->
		<!--[if lte IE 6]><table><tr><td><![endif]-->
		<div class="select_sub">
			<ul class="sub">
				<li><a href="<c:url value="/admin/update_order.jsp" />">Cập Nhật Trạng Thái Đơn Hàng</a></li>
			 
			</ul>
		</div>
		<!--[if lte IE 6]></td></tr></table></a><![endif]-->
		</li>
		</ul>		
		
		<div class="clear"></div>
		</div>
		<div class="clear"></div>
		</div>
		<!--  start nav -->

</div>
<div class="clear"></div>
<!--  start nav-outer -->
</div>
<!--  start nav-outer-repeat................................................... END -->

 <div class="clear"></div>
 
<!-- start content-outer ........................................................................................................................START -->
<div id="content-outer">
<!-- start content -->
<div id="content">

	<!--  start page-heading -->
	<div id="page-heading">
		<h1>Thêm Sản Phẩm</h1>
	</div>
	<!-- end page-heading -->

	<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
	<tr>
		<th rowspan="3" class="sized"><img src="<c:url value="/layout/default/shared/side_shadowleft.jpg" />" width="20" height="300" alt="" /></th>
		<th class="topleft"></th>
		<td id="tbl-border-top">&nbsp;</td>
		<th class="topright"></th>
		<th rowspan="3" class="sized"><img src="<c:url value="/layout/default/shared/side_shadowright.jpg" />" width="20" height="300" alt="" /></th>
	</tr>
	<tr>
		<td id="tbl-border-left"></td>
		<td>
		<!--  start content-table-inner ...................................................................... START -->
		<div id="content-table-inner">
                    
			<!--  start table-content  -->
			<div id="table-content">
<% 
String ProductID = "";
String ProductName = "";
String ImageName = "";
String QOH = "0";
String UnitPrice = "0";
String CategoryID = "";
if(request.getAttribute("ProductID") != null) {
    ProductID = request.getAttribute("ProductID").toString();
    ImageName = ProductID + ".jpg";
}
if(request.getAttribute("ProductName") != null) {
    ProductName = request.getAttribute("ProductName").toString();
}
if(request.getAttribute("QOH_str") != null) {
    QOH = request.getAttribute("QOH_str").toString();
}
if(request.getAttribute("UnitPrice_str") != null) {
    UnitPrice = request.getAttribute("UnitPrice_str").toString();
}
if(request.getAttribute("CategoryID") != null) {
    CategoryID = request.getAttribute("CategoryID").toString();
}
%>
<ul style="margin-left: 20px;margin-bottom: 20px;">
<% if(request.getAttribute("errorMsgs") != null) {
    List errorMsgs = (List) request.getAttribute("errorMsgs");
    Iterator errorMsg = errorMsgs.iterator();
    while(errorMsg.hasNext()) { 
        String error = errorMsg.next().toString(); %>
        <i style='color:red'><li><%=error%></li></i>
<% } } %>
</ul>
<form name="form1" method="post" action="<c:url value="/admin/add_product.do" />">			
		<!-- start id-form -->
		<table border="0" cellpadding="0" cellspacing="0"  id="id-form">
		<tr>
			<th valign="top"><span style="color: red;">*&nbsp;</span>Mã Sản Phẩm:</th>
			<td><input type="text" class="inp-form" name="ProductID" value="<%=ProductID%>"/></td>
			<td rowspan="4"><img src='../images/products/<%=ImageName%>' width=180 height=150/></td>
		</tr>
		<tr>
			<th valign="top"><span style="color: red;">*&nbsp;</span>Tên Sản Phẩm:</th>
			<td><input type="text" class="inp-form" name="ProductName" value="<%=ProductName%>"/></td>
			<td></td>
		</tr>
		<tr>
			<th valign="top"><span style="color: red;">*&nbsp;</span>Số Lượng Tồn Kho:</th>
			<td><input type="text" class="inp-form" name="QOH" value="<%=QOH%>" style="text-align:right"/></td>
			<td></td>
		</tr>                
		<tr>
			<th valign="top"><span style="color: red;">*&nbsp;</span>Đơn Giá:</th>
			<td><input type="text" class="inp-form" name="UnitPrice" value="<%=UnitPrice%>" style="text-align:right"/></td>
			<td></td>
		</tr>
                		<tr>
		<th valign="top"><span style="color: red;">*&nbsp;</span>Loại Sản Phẩm:</th>
                <td colspan="2">	
                    <div style="float:left;"><select name='CategoryID' class="styledselect_form_1">
                    <option value="0">-- chọn --</option>
            <% 
                CategoryServiceLocal categoryServiceLocal = (CategoryServiceLocal) application.getAttribute("categoryServiceLocal");
                List<Category> lstCategories = categoryServiceLocal.getAllCategories();
                for(int i = 0; i < lstCategories.size(); i++) {
                    String cid = lstCategories.get(i).getCategoryID();
                    String cname = lstCategories.get(i).getCategoryName(); 
                    if(cid.equals(CategoryID)) {  %>                     
                    <option value="<%=cid%>" selected="true"><%=cname%></option>
               <% } else { %>                   
                    <option value="<%=cid%>"><%=cname%></option>
               <% } } %>
		</select></div>
               <div style="float:left;padding-top: 8px;padding-left: 15px;"><a href="<c:url value="/admin/add_category.jsp" />">Thêm Loại Sản Phẩm Mới</a></div>
		</td>
		<td></td>
		</tr> 
	<tr>
	<th>Hình Ảnh:</th>
	<td><input type="file" class="file_1"/></td>
	<td>
	<div class="bubble-left"></div>
	<div class="bubble-inner">Tải Hình</div>
	<div class="bubble-right"></div>
        <div style="float:left;margin-left: 20px;"><input type="submit" class="button lightText small regular black" name="btnSubmit" value="Thêm" /></div>
	</td>
	</tr>
	</table>
	<!-- end id-form  -->
</form>                        
			</div>
			<!--  end content-table  -->				
			
			<div class="clear"></div>
		 
		</div>
		<!--  end content-table-inner ............................................END  -->
		</td>
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
	</table>
	<div class="clear">&nbsp;</div>

</div>
<!--  end content -->
<div class="clear">&nbsp;</div>
</div>
<!--  end content-outer........................................................END -->
<% 
if(((HttpServletRequest) request).getAttribute("notify") != null) {
    String notify = ((HttpServletRequest) request).getAttribute("notify").toString();
    if(notify.length() > 0) { 
        out.println("<script type=\"text/javascript\">");
        out.println("alert(\"" + notify + "\")");
        out.println("</script>");
    }
} %>
